package net.za.cair.dip.util;

import java.util.HashSet;
import java.util.Set;

/*
 * Copyright (C) 2011, Centre for Artificial Intelligence Research
 *
 * Modifications to the initial code base are copyright of their
 * respective authors, or their employers as appropriate.  Authorship
 * of the modifications may be determined from the ChangeLog placed at
 * the end of this file.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

/**
 * Authors: Kody Moodley<br>
 * Centre for Artificial Intelligence Research<br>
 * Knowledge Representation and Reasoning Group<br>
 * Date: July-2013<br><br>
 */

public class OrderedPair<T> {
	public T subject;
	public T object;
	
	public OrderedPair(){
		subject = null;
		object = null;
	}
	
	public OrderedPair(T subj, T obj){
		subject = subj;
		object = obj;
	}
	
	public boolean equals(OrderedPair<T> pair){
		if (subject.equals(pair.subject) && object.equals(pair.object))
			return true;
		return false;
	}
	
	public String toString(){
		return subject + ": " + object + "\n";
	}
	
	public boolean isContainedIn(Set<OrderedPair<T>> set){
		for (OrderedPair<T> current: set){
			if (current.equals(this))
				return true;
		}
		return false;
	}
	
	public static void main(String [] args){
		Set<OrderedPair<Character>> orderedPairs = new HashSet<OrderedPair<Character>>();
		
		OrderedPair<Character> pair1 = new OrderedPair<Character>('a','b');
		orderedPairs.add(pair1);
		
		OrderedPair<Character> pair2 = new OrderedPair<Character>('a','b');
		orderedPairs.add(pair2);
		
		OrderedPair<Character> pair3 = new OrderedPair<Character>('c','b');
		orderedPairs.add(pair3);
		
		OrderedPair<Character> pair4 = new OrderedPair<Character>('a','b');
		orderedPairs.add(pair4);
		
		OrderedPair<Character> pair5 = new OrderedPair<Character>('e','f');
		orderedPairs.add(pair5);
		
		OrderedPair<Character> pair6 = new OrderedPair<Character>('b','a');
		orderedPairs.add(pair6);
		
		OrderedPair<Character> pair7 = new OrderedPair<Character>('e','f');
		
		System.out.println(orderedPairs.size());
		
		System.out.println(pair7.isContainedIn(orderedPairs));
		
		/*orderedPairs.add(new OrderedPair<Character>('a','b'));
		
		orderedPairs.add(new OrderedPair<Character>('b','a'));
		orderedPairs.add(new OrderedPair<Character>('c','d'));
		orderedPairs.add(new OrderedPair<Character>('d','e'));
		orderedPairs.add(new OrderedPair<Character>('f','g'));
		orderedPairs.add(new OrderedPair<Character>('g','d'));
		
		System.out.println(orderedPairs);
		
		Set<OrderedPair<Character>> newOrderedPairs = new HashSet<OrderedPair<Character>>(orderedPairs);
		
		OrderedPair<Character> tmp = new OrderedPair<Character>();
		for (OrderedPair<Character> pair: orderedPairs){
			tmp.subject = pair.subject;
			tmp.object = pair.object;
			newOrderedPairs.add(tmp);
		}
		
		System.out.println();
		
		System.out.println(newOrderedPairs);*/
		
	}
}
